
<div id="form_main_wrap" class="form_main_wrap">
	<div id="roleswrap" style="padding: 30px 14px;">

	</div>
</div>

<script type="application/javascript" th:inline="javascript">

	
	$B.DomUtils.onDomLoaded(function(){
		var userRoles = [(${userRoles})],
			rolesJson = [(${rolesJson})],
				userId = '[(${userId})]';
		//console.log(userRoles,rolesJson,userId);
		var wrap = document.getElementById("roleswrap");
		for(var i = 0, len = rolesJson.length ; i < len ;++i){
			var role = rolesJson[i];
			var checked = "";
			for(var j = 0 ,jlen = userRoles.length ; j < jlen ;++j){
				if(userRoles[j].roleId === role.id){
					checked = 'checked="checked"';
					break;
				}
			}
			$B.DomUtils.append(wrap,'<label class="k_checkbox_label k_checkbox_anim">'
                        +'<input type="checkbox" '+checked+' name="hobby" value="'+role.id+'" /><i class="k_checkbox_i"></i>'+role.roleName+'</label>');
		}
		if(rolesJson.length === 0){
			$B.DomUtils.append(wrap,'<label class="k_checkbox_label k_checkbox_anim" style="padding: 2px 12px"><i style="color:red;padding: 0 12px" class="fa fa-attention-alt"></i>无可用角色！</label>');
		}
		window.saveUserRoleFn = function (btn,$w) {
			var childs = wrap.children;
			var roleIds = [];
			for(let i =0 ; i < childs.length ;i++){
				let $chk = childs[i].firstChild;
				if($chk.checked){
					roleIds.push($chk.value);
				}
			}
			$B.request({
				data:{
					userId:userId,
					roleIds:roleIds.join(",")
				},
				url:$B.getHttpHost(ctxPath)+"user/roleUpdate?cmd=roleUpdate",
				ok:function(){
					$B.success('[(${Lang.common_saveSucess})]',1.2);
					curdObj.refresh();
					$w.close();
				}
			},btn);
		};
		
	});
	
</script>